<?php

namespace App\Models\Lst;

use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait;

class Publish extends Model
{
    use PresentableTrait;

	protected $table = 'lst_publishs';

    protected $guarded = array();

    protected $presenter = 'App\Http\Presenters\DeployPresenter';

    public function details()
    {
        return $this->hasMany('\App\Models\Lst\Detail');
    }


    public function branch()
    {
        return $this->hasOneThrough('\App\Models\Mgt\Branch','\App\Models\Edu\Term','id','id','term_id','branch_id');
    }


    public function type()
    {
        return $this->hasOneThrough('\App\Models\Edu\Type','\App\Models\Edu\Term','id','id','term_id','type_id');
    }


    public function term()
    {
        return $this->belongsTo('\App\Models\Edu\Term','term_id');
    }


    public function getBranchs($typeid)
    {
        return $this->where('type_id', $typeid)->select('branch_id')->distinct()->get();
    }

}